<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Show detailed information of an note (news).
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.1
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_action.php';
require_once INSTALLDIR . '/lib/slh_util.php';

require_once INSTALLDIR . '/classes/User.php';
require_once INSTALLDIR . '/classes/NoteNews.php';


class NoteAction extends Action
{
	/**
	 * The NoteNews
	 */
	var $notenews = null;
	
	
	function title()
	{
		return '记事新闻';
	}
	
	function prepare($args)
	{
// TODO: Check logged in and rights.
		parent::prepare($args);
		
		// Parameter from 'get' url
		$news_id = $this->getTrimmedArg('gnews_id');
		
		if ( !is_numeric($news_id)) {
			return false;
		}
		
		// Get the note(news).
		$this->notenews = NoteNews::staticGet('news_id', $news_id);
		if (empty($this->notenews)) {
			$this->clientError('没有这个记事新闻呃.');
		}
		
		return true;
	}
	
	function handle($args)
	{
		parent::handle($args);

		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			;
		} else {
			// Increase the 'viewcn' at 'data'.
			$this->notenews->increaseViewCount();
			
			$this->showPage();
		}
	}
	
	/**
	 * Overrideing the showInnerContent().
	 */
	function showInnerContent()
	{
		$this->element('h3', null, '@记事新闻');
		
		$this->elementStart('div', 'cls_div_note');
		$this->elementStart('div', 'cls_div_message');
		$this->raw('<span class="message">' .
				   $this->notenews->message . 
				   '</span>');
		$this->elementEnd('div');
		
		$this->element('h5', null, '详细内容: ');
		
		$this->raw('<span class="cls_span_noteitem">' .
				   '录入: ' .
				   User::getTitleByUserid($this->notenews->user_id) . 
				   '</span>');
		
		$this->raw('<span class="cls_span_noteitem">' .
				   '浏览次数: ' .
				   $this->notenews->viewcnt . 
				   '</span>');
		
		$this->raw('<span class="cls_span_noteitem">' .
				   '发布时间: ' .
				   $this->notenews->created . 
				   '</span>');
				   
		$this->elementStart('div', 'cls_div_rendered');
		$this->raw(slh_uncompress($this->notenews->rendered));
		$this->elementEnd('div');
		
		$this->elementEnd('div');
	}
	
// Overrided ends //////////////////////////////////////////////////////////////	
	/**
	 * Remove the aside.
	 */
	/*
	function showAsideBlock()
	{}
	*/
}

?>